﻿using Autofac;
using project.B12.application.ViewModels;
using project.B12.application.ViewModels.Dialogs;
using project.B12.application.ViewModels.Setting;
using project.B12.application.Views.Dialogs;
using project.B12.IService;
using project.B12.Repository.Base;
using project.B12.Service;
using project.B12.Service.UserService;
using project.B12.ViewModels;

namespace project.B12.application.Ioc
{
    /// <summary>
    /// 容器
    /// </summary>
    public class IocContainer
    {
        /// <summary>
        /// 容器
        /// </summary>
        public static IContainer Instance;

        /// <summary>
        /// 初始化容器
        /// </summary>
        /// <returns></returns>
        public static void Init()
        {
            //新建容器构建器，用于注册组件和服务
            var builder = new ContainerBuilder();
            //自定义注册
            MyBuild(builder);
            //利用构建器创建容器
            Instance = builder.Build();
        }

        /// <summary>
        /// 自定义注册
        /// </summary>
        /// <param name="builder"></param>
        public static void MyBuild(ContainerBuilder builder)
        {
            builder.RegisterType<SugarDbContext>().SingleInstance();
            builder.RegisterType<PublicResourceViewModel>().SingleInstance();
            builder.RegisterType<MainWindowViewModel>().SingleInstance();
            builder.RegisterType<MainViewModel>().SingleInstance();
            builder.RegisterType<LoginViewModel>().SingleInstance();
            builder.RegisterType<MonitorViewModel>().SingleInstance();

            builder.RegisterType<AddSampleViewModel>().SingleInstance();
            builder.RegisterType<LogViewModel>().SingleInstance();
            builder.RegisterType<AnalyseViewModel>().SingleInstance();
            builder.RegisterType<UserSettingViewModel>().SingleInstance(); 
            builder.RegisterType<DeviceSettingViewModel>().SingleInstance();
            builder.RegisterType<LanguageSettingViewModel>().SingleInstance();
            builder.RegisterType<ResetPasswordViewModel>().SingleInstance();
            builder.RegisterType<ExpirationTimeViewModel>().SingleInstance();
            builder.RegisterType<AddPlateIdViewModel>().SingleInstance();
            builder.RegisterType<AddPlateId>().SingleInstance();

            builder.RegisterType<DBDataViewModel>().SingleInstance();
            builder.RegisterType<BacteriaViewModel>().SingleInstance();
            builder.RegisterType<MedicineViewModel>().SingleInstance();
            builder.RegisterType<SIRViewModel>().SingleInstance();
            builder.RegisterType<ExcelExportViewModel>();
            builder.RegisterType<DisinfectionProtectionViewModel>();
            builder.RegisterType<ProjectRuleSettingViewModel>();
            builder.RegisterType<SpecialSampleViewModel>();
            builder.RegisterType<ReportExportTemplateViewModel>();

            // 反射注册
            builder.RegisterModule(new AutofacModuleRegister());
            //builder.RegisterType<DeviceVirtualService>().As<IDeviceService>();
            //builder.RegisterType<ServiceDevice>().As<IServiceCam>();
        }
    }
}